﻿using Jquery.IDAL;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;

namespace Jquery.DAL
{
    /// <summary>
    /// 相当于简单工厂 可以拿到所有的仓储实例 ，对整个数据库访问层高度抽象，统一入口
    /// </summary>
    public class DBsession : IDBsession
    {
        //有多个库的时候可以用DbContext
        //public DbContext db = new DBjquery();
        public DbContext dbSesstion
        {
            get
            {
                return DbContextFactory.GetCurrentThreadDbContext(); 
            }
        }
        private IActionRepository actionRepository;
        public IActionRepository ActionRepository
        {
            get
            {
                if (actionRepository == null)
                {
                    actionRepository = new ActionRepository();
                }
                return actionRepository;
            }
            set { actionRepository = value; }
        }
        public int ExcuteSql(string sql, params object[] parameters)
        {
            return 1;
            //return db.Database.SqlQuery(System.Type.GetType("System.Int32"), sql, parameters);
        }
        public int SaveChange()
        {
            return dbSesstion.SaveChanges();
        }
    }
}
